//
//  StoreGoodsSection.m
//  KYRR
//
//  Created by kuyuZJ on 2017/4/22.
//
//

#import "StoreGoodsSection.h"

@interface StoreGoodsSection ()
@property(nonatomic,strong) UILabel* labelLine;
@property(nonatomic,strong) UILabel* labelLeft;
@property(nonatomic,strong) UILabel* labelType;

@end

@implementation StoreGoodsSection{
    CGSize leftSize;
}

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if(self){
        self.contentView.backgroundColor = [UIColor whiteColor];
        leftSize = CGSizeMake(2.f, 10.f);
        
        
        [self.contentView addSubview:self.labelLeft];
        [self.contentView addSubview:self.labelType];
        [self.contentView addSubview:self.labelLine];
        
        NSArray<NSString*>* formats = @[@"H:|-leftEdge-[labelLeft(==leftWidth)]-5-[labelType]-defEdge-|",
                                        @"V:[labelLeft(==leftHeight)]", @"V:|-topEdge-[labelType]-topEdge-|",
                                        @"H:|-defEdge-[labelLine]-defEdge-|", @"V:|-defEdge-[labelLine(==1)]"
                                        ];
        NSDictionary<NSString*,id>* metrics = @{ @"defEdge":@(0), @"leftEdge":@(10), @"topEdge":@(10),
                                                 @"leftWidth":@(leftSize.width), @"leftHeight":@(leftSize.height)};
        NSDictionary<NSString*,id>* views = @{ @"labelLeft":self.labelLeft, @"labelType":self.labelType, @"labelLine":self.labelLine};
        [formats enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog( @"%@ %@",[self class],obj);
            NSArray<NSLayoutConstraint*>* constraints = [NSLayoutConstraint constraintsWithVisualFormat:obj options:0 metrics:metrics views:views];
            [self.contentView addConstraints:constraints];
        }];
        [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelLeft attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.f]];
    }
    return self;
}

-(void)setEntity:(MGoodsType *)entity{
    if(entity){
        _entity = entity;
        self.labelType.text = self.entity.catename;
    }
}

#pragma mark =====================================================  property package

-(UILabel *)labelLeft{
    if(!_labelLeft){
        UILabel* empty = [[UILabel alloc]init];
        empty.backgroundColor = theme_navigation_color;
        empty.translatesAutoresizingMaskIntoConstraints =NO;
        _labelLeft = empty;
    }
    return _labelLeft;
}

-(UILabel *)labelType{
    if(!_labelType){
        UILabel* empty = [[UILabel alloc]init];
        empty.font = [UIFont systemFontOfSize:14.f];
        empty.translatesAutoresizingMaskIntoConstraints =NO;
        _labelType = empty;
    }
    return _labelType;
}

-(UILabel *)labelLine{
    if(!_labelLine){
        UILabel* empty = [[UILabel alloc]init];
        empty.backgroundColor = theme_line_color;
        empty.translatesAutoresizingMaskIntoConstraints =NO;
        _labelLine = empty;
        
    }
    return _labelLine;
}

@end
